package com.ymatou.iapi.dguser.testcase;

import com.ymatou.iapi.dguser.parameter.UpdateLastLoginTimeBean;
import com.ymatou.iapi.dguser.service.UpdateLastLoginTimeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Date;

/**
 * 更新最后登录时间 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_UpdateLastLoginTime {
	private static UpdateLastLoginTimeBean updatelastlogintimeBean;
	private static UpdateLastLoginTimeCall updatelastlogintimeCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新最后登录时间");
	}

	@Before
	public void caseUp() {
		updatelastlogintimeBean = new UpdateLastLoginTimeBean();
		updatelastlogintimeCall = new UpdateLastLoginTimeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatelastlogintimeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UpdateLastLoginTime_001() {
		Logger.start(true, "更新最后登录时间");
		try {
			// UserCreateBean u = DGUserCallService.initUsercreateBean();
			// int user = DGUserCallService.UserCreateCall(u);
			DGUserWapper DGUserWapper = new DGUserWapper();
			int userid = 500000000;
			DGUserInfo dgUserInfo = DGUserWapper.selectDGUserInfo(userid).get(0);
			Date lt1 = dgUserInfo.getLastLoginTime();
			Thread.sleep(1000);
			updatelastlogintimeBean.setUserId(userid);
			updatelastlogintimeCall.setData(updatelastlogintimeBean);
			updatelastlogintimeCall.callService();
			Logger.verifyEquals("true", updatelastlogintimeCall.getString("success"), "验证success");
			dgUserInfo = DGUserWapper.selectDGUserInfo(userid).get(0);
			Date lt2 = dgUserInfo.getLastLoginTime();
			Logger.verifyNotEquals(lt1, lt2, "更新时间");
		} catch (Exception e) {
			Logger.fail(e);
		} catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
}